package gui;

import java.awt.Dimension;
import java.awt.TextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SpinnerListModel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ConsultaSala extends javax.swing.JPanel {
	private JLabel dadosSalas;
	private JButton botaoVoltar;
	private JLabel campoMenor;
	private JLabel campoMaior;
	private JButton botaoAltera;
	private JTextField campoIdentificacao;
	private JLabel alteraSala;
	private TextArea jTextArea1;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new ConsultaSala());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public ConsultaSala() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(800, 600));
			this.setSize(800, 600);
			this.setBackground(new java.awt.Color(204,204,255));
			this.setLayout(null);
			{
				dadosSalas = new JLabel();
				this.add(dadosSalas);
				dadosSalas.setText("Consultar Dados Das Salas");
				dadosSalas.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				dadosSalas.setFont(new java.awt.Font("Arial",0,36));
				dadosSalas.setForeground(new java.awt.Color(0,104,104));
				dadosSalas.setBounds(179, 5, 442, 47);
			}
			{
				jTextArea1 = new TextArea();
				this.add(jTextArea1);
				jTextArea1.setBounds(73, 124, 386, 405);
				String dados="";
				for(int i=0;i<GerenciadorDeJanelas.todasSalas.size();i++){
					dados = dados+"\n"+GerenciadorDeJanelas.todasSalas.get(i).toString();
				}
				jTextArea1.setText(dados);
				jTextArea1.setEditable(false);
				jTextArea1.setFont(new java.awt.Font("Arial",0,18));
				jTextArea1.setForeground(new java.awt.Color(0,0,0));
			}
			{
				alteraSala = new JLabel();
				this.add(alteraSala);
				alteraSala.setText("Alterar Dados :");
				alteraSala.setBounds(553, 141, 126, 19);
				alteraSala.setFont(new java.awt.Font("Arial",0,18));
				alteraSala.setForeground(new java.awt.Color(0,104,104));
			}
			{
				campoIdentificacao = new JTextField();
				this.add(campoIdentificacao);
				campoIdentificacao.setText("Identificacao Da Sala");
				campoIdentificacao.setBounds(528, 172, 178, 28);
				campoIdentificacao.setFont(new java.awt.Font("Arial",0,18));
				campoIdentificacao.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
						campoIdentificacao.setText("");
				}
			});
			}
			{
				botaoAltera = new JButton();
				this.add(botaoAltera);
				botaoAltera.setText("Alterar");
				botaoAltera.setBounds(559, 212, 112, 28);
				botaoAltera.setFont(new java.awt.Font("Arial",2,18));
				botaoAltera.setBackground(new java.awt.Color(255,255,255));
				botaoAltera.addMouseListener(new java.awt.event.MouseAdapter() {
		            public void mouseClicked(java.awt.event.MouseEvent evt){
		                try{
		                	alteraMouseClicked(evt);}
		                catch(Exception e){
		                	System.out.println(e.getMessage());
		                }
		            }
		        });
			}
			{
				botaoVoltar = new JButton();
				this.add(botaoVoltar);
				botaoVoltar.setText("Voltar");
				botaoVoltar.setBounds(559, 331, 112, 29);
				botaoVoltar.setFont(new java.awt.Font("Arial",2,18));
				botaoVoltar.setBackground(new java.awt.Color(255,255,255));
				botaoVoltar.addMouseListener(new java.awt.event.MouseAdapter() {
		            public void mouseClicked(java.awt.event.MouseEvent evt){
		                try{
		                	voltarMouseClicked(evt);}
		                catch(Exception e){
		                	System.out.println(e.getMessage());
		                }
		            }
		        });
			}
			{
				campoMaior = new JLabel();
				this.add(campoMaior);
				campoMaior.setBounds(37, 89, 721, 480);
				campoMaior.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
			}
			{
				campoMenor = new JLabel();
				this.add(campoMenor);
				campoMenor.setBounds(478, 102, 23, 449);
				campoMenor.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void alteraMouseClicked(java.awt.event.MouseEvent evt){
		String ident = campoIdentificacao.getText();
		int identificacao = 0;
		try{
			identificacao = Integer.parseInt(ident);
			for (int i=0;i<GerenciadorDeJanelas.todasSalas.size();i++){
				if(GerenciadorDeJanelas.todasSalas.get(i).getNumeroDeIdentificacao()==identificacao){
					GerenciadorDeJanelas.window.setVisible(false);
					GerenciadorDeJanelas.alteraSala = new AlteraSala();
					AlteraSala.posicao = i;
			        GerenciadorDeJanelas.window.setContentPane(GerenciadorDeJanelas.alteraSala);
			        GerenciadorDeJanelas.window.setVisible(true);
			        campoIdentificacao.setText("Identificacao Da Sala");
				}
			}
		}
		catch(Exception e){
			JOptionPane.showMessageDialog(null,"Identificacao da sala invalida, ou sala nao existente. Por favor, cheque novamente as informacoes digitadas.");
		}
	}
	
	public void voltarMouseClicked(java.awt.event.MouseEvent evt){
		GerenciadorDeJanelas.window.setVisible(false);
        GerenciadorDeJanelas.window.setContentPane(GerenciadorDeJanelas.menuAltera);
        GerenciadorDeJanelas.window.setVisible(true);
        campoIdentificacao.setText("Identificacao Da Sala");
	}

}
